package model

import (
	"time"
)

// User 用户模型
type User struct {
	BaseModel
	Username     string    `json:"username" gorm:"size:50;not null;unique"`
	Password     string    `json:"-" gorm:"size:100;not null"`
	Nickname     string    `json:"nickname" gorm:"size:50"`
	Avatar       string    `json:"avatar" gorm:"size:255"`
	Email        string    `json:"email" gorm:"size:100"`
	Phone        string    `json:"phone" gorm:"size:20"`
	Gender       int       `json:"gender" gorm:"default:0"`
	Birthday     time.Time `json:"birthday" gorm:"type:date"`
	Introduction string    `json:"introduction" gorm:"size:255"`
	Status       int       `json:"status" gorm:"default:1"`
	LastLoginAt  time.Time `json:"last_login_at"`
	LastLoginIP  string    `json:"last_login_ip" gorm:"size:50"`
	RoleID       uint      `json:"role_id" gorm:"default:0"` // 角色ID
}

// TableName 表名
func (User) TableName() string {
	return "users"
}

// UserRole 用户角色
type UserRole struct {
	BaseModel
	UserID uint `json:"user_id" gorm:"not null"`
	RoleID uint `json:"role_id" gorm:"not null"`
}

// TableName 表名
func (UserRole) TableName() string {
	return "user_roles"
}

// Role 角色模型
type Role struct {
	BaseModel
	Name        string `json:"name" gorm:"size:50;not null;unique"`
	Description string `json:"description" gorm:"size:255"`
	Status      int    `json:"status" gorm:"default:1"`
}

// TableName 表名
func (Role) TableName() string {
	return "roles"
}

// Permission 权限模型
type Permission struct {
	BaseModel
	Name        string `json:"name" gorm:"size:50;not null;unique"`
	Description string `json:"description" gorm:"size:255"`
	Path        string `json:"path" gorm:"size:255"`
	Method      string `json:"method" gorm:"size:10"`
	Status      int    `json:"status" gorm:"default:1"`
}

// TableName 表名
func (Permission) TableName() string {
	return "permissions"
}

// RolePermission 角色权限关联
type RolePermission struct {
	BaseModel
	RoleID       uint `json:"role_id" gorm:"not null"`
	PermissionID uint `json:"permission_id" gorm:"not null"`
}

// TableName 表名
func (RolePermission) TableName() string {
	return "role_permissions"
}
